package cn.edu.wfit.modules.learn.controller.projectmanagement;

import java.util.List;

import cn.edu.wfit.modules.learn.domain.WfitSource;
import cn.edu.wfit.modules.learn.service.projectmanagement.IWfitSourceService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.edu.wfit.common.log.annotation.Log;
import cn.edu.wfit.common.log.enums.BusinessType;
import cn.edu.wfit.common.security.annotation.RequiresPermissions;

import cn.edu.wfit.common.core.web.controller.BaseController;
import cn.edu.wfit.common.core.web.domain.AjaxResult;
import cn.edu.wfit.common.core.utils.poi.ExcelUtil;
import cn.edu.wfit.common.core.web.page.TableDataInfo;

/**
 * 项目成员分数Controller
 * 
 * @author ruoyi
 * @date 2025-07-25
 */
@RestController
@RequestMapping("/source")
public class WfitSourceController extends BaseController
{
    @Autowired
    private IWfitSourceService wfitSourceService;
    /**
     * 查询项目成员分数列表
     */
    @RequiresPermissions("system:source:list")
    @GetMapping("/list")
    public TableDataInfo list(WfitSource wfitSource)
    {
        startPage();
        List<WfitSource> list = wfitSourceService.selectWfitSourceList(wfitSource);
        return getDataTable(list);
    }

    /**
     * 导出项目成员分数列表
     */
    @RequiresPermissions("system:source:export")
    @Log(title = "项目成员分数", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WfitSource wfitSource)
    {
        List<WfitSource> list = wfitSourceService.selectWfitSourceList(wfitSource);
        ExcelUtil<WfitSource> util = new ExcelUtil<WfitSource>(WfitSource.class);
        util.exportExcel(response, list, "项目成员分数数据");
    }

    /**
     * 获取项目成员分数详细信息
     */
    @RequiresPermissions("system:source:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wfitSourceService.selectWfitSourceById(id));
    }

    /**
     * 新增项目成员分数
     */
    @RequiresPermissions("system:source:add")
    @Log(title = "项目成员分数", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WfitSource wfitSource)
    {
        //获得成员分数信息,调用新的ProjectLog,为日志表也添加一条数据
        return toAjax(wfitSourceService.insertWfitSource(wfitSource));
    }

    /**
     * 修改项目成员分数
     */
    @RequiresPermissions("system:source:edit")
    @Log(title = "项目成员分数", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WfitSource wfitSource)
    {
        return toAjax(wfitSourceService.updateWfitSource(wfitSource));
    }

    /**
     * 删除项目成员分数
     */
    @RequiresPermissions("system:source:remove")
    @Log(title = "项目成员分数", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wfitSourceService.deleteWfitSourceByIds(ids));
    }
}
